AtCoder Beginner Contest 326

2UP3DOWN

1
2
3
4
5
6
7
8
public static void solve() {
int x = io.nextInt(), y = io.nextInt();
if (y - x >= -3 && y - x <= 2) {
io.println("Yes");
} else {
io.println("No");
}
}

326-like Numbers

1
2
3
4
5
6
7
8
9
public static void solve() {
int n = io.nextInt();
for (; ; n++) {
if (n / 100 * (n / 10 % 10) == n % 10) {
io.println(n);
return;
}
}
}

Peak

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public static void solve() {
int n = io.nextInt(), m = io.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = io.nextInt();
}
Arrays.sort(a);

int ans = 0;
for (int i = 0, j = 0; j < n; j++) {
while (a[j] - a[i] >= m) {
i++;
}
ans = Math.max(ans, j - i + 1);
}
io.println(ans);
}

ABC Puzzle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
public static void solve() {
int n = io.nextInt();
char[] r = io.next().toCharArray();
char[] c = io.next().toCharArray();

int[] row = new int[n];
int[] col = new int[n];
char[][] ans = new char[n][n];
for (int i = 0; i < n; i++) {
Arrays.fill(ans[i], '.');
}
boolean ok = dfs(0, 0, r, c, ans, row, col, 0);

if (!ok) {
io.println("No");
return;
}
io.println("Yes");
for (int i = 0; i < n; i++) {
io.println(new String(ans[i]));
}
}

private static boolean dfs(int x, int y, char[] r, char[] c, char[][] ans, int[] row, int[] col, int cnt) {
int n = r.length;
if (x == n) {
return cnt == 3 * n;
}
if (n - 1 - y >= 3 - Integer.bitCount(row[x])) {
if (dfs(x + (y + 1) / n, (y + 1) % n, r, c, ans, row, col, cnt)) {
return true;
}
}
for (int i = 0; i < 3; i++) {
if ((row[x] >> i & 1) == 1 || (col[y] >> i & 1) == 1) {
continue;
}
if (row[x] == 0 && r[x] != 'A' + i) {
continue;
}
if (col[y] == 0 && c[y] != 'A' + i) {
continue;
}
row[x] |= 1 << i;
col[y] |= 1 << i;
ans[x][y] = (char) ('A' + i);
if (dfs(x + (y + 1) / n, (y + 1) % n, r, c, ans, row, col, cnt + 1)) {
return true;
}
row[x] ^= 1 << i;
col[y] ^= 1 << i;
ans[x][y] = '.';
}
return false;
}

Revenge of “The Salary of AtCoder Inc.”

概率 DP,答案为 \(\sum_{i=1}^{n}{A_{i}P_{i}}\),而 \(P_{i}=\frac{1}{N}\sum_{j=0}^{i-1}{P_{j}}=P_{i-1}+\frac{1}{N}P_{i-1}\)。(这么简单,真没想到)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
private static final int MOD = 998244353;

public static void solve() {
int n = io.nextInt();
long invn = pow(n, MOD - 2);
long ans = 0L, p = invn;
for (int i = 0; i < n; i++) {
int a = io.nextInt();
ans = (ans + p * a) % MOD;
p = (p + invn * p) % MOD;
}
io.println(ans);
}

private static long pow(long x, long n) {
long res = 1L;
for (; n != 0; x = x * x % MOD, n >>= 1) {
if ((n & 1) == 1) {
res = res * x % MOD;
}
}
return res;
}
作者

Ligh0x74

发布于

2023-10-29

更新于

2023-10-29

许可协议

评论